package com.hmall.order.web;

import com.hmall.common.client.ItemClient;
import com.hmall.common.client.UserClient;
import com.hmall.common.dto.Address;
import com.hmall.common.dto.Item;
import com.hmall.order.config.UserContextHolder;
import com.hmall.order.constants.MqConstants;
import com.hmall.order.pojo.Order;
import com.hmall.order.pojo.OrderDetail;
import com.hmall.order.pojo.OrderLogistics;
import com.hmall.order.pojo.RequestParams;
import com.hmall.order.service.IOrderDetailService;
import com.hmall.order.service.IOrderService;
import com.hmall.order.service.OrderLogisticsService;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("order")
public class OrderController {
    @Autowired
    private IOrderService orderService;

    @GetMapping("{id}")
    public Order queryOrderById(@PathVariable("id") Long orderId) {
        return orderService.getById(orderId);
    }

    @GetMapping("/num/{id}")
    public OrderDetail getOrderDetail(@PathVariable("id") Long orderId) {
        return orderService.getOrderDetail(orderId);
    }

    @PutMapping("/status/{id}")
    public int cancelOrder(@PathVariable("id") Long orderId) {
        return orderService.cancelOrder(orderId);
    }
    @PutMapping("/payisOk/{id}")
    public int payisOk(@PathVariable("id") Long orderId) {
        return orderService.payisOk(orderId);
    }

    @GetMapping("/status/{id}")
    public int getStatus(@PathVariable("id") Long orderId) {
        return orderService.findStatusById(orderId);
    }

    /**
     * 生成订单
     *
     * @param params
     * @return
     */
    @PostMapping
    public String addOrder(@RequestBody RequestParams params) {
       return orderService.addOrder(params);
    }
}
